
//	MIT License
//
//	Copyright (c) 2017 Matej Artnak
//
//	Permission is hereby granted, free of charge, to any person obtaining a copy
//	of this software and associated documentation files (the "Software"), to deal
//	in the Software without restriction, including without limitation the rights
//	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//	copies of the Software, and to permit persons to whom the Software is
//	furnished to do so, subject to the following conditions:
//
//	The above copyright notice and this permission notice shall be included in all
//	copies or substantial portions of the Software.
//
//	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//	SOFTWARE.
//
//
// Modyfy to ILI9488 by NSJ
//
//-----------------------------------

#ifndef ILI9488_HAL_SPI_H
#define ILI9488_HAL_SPI_H

#include "stm32f1xx_hal.h"


#define LCD_BK_Pin GPIO_PIN_9		          //
#define LCD_BK_GPIO_Port GPIOB

#define LCD_RS_Pin GPIO_PIN_10            // RS=0 命令; RS=1 数据; 原来PC5
#define LCD_RS_GPIO_Port GPIOB

#define LCD_CS_Pin GPIO_PIN_11		        //原来PA4
#define LCD_CS_GPIO_Port GPIOB

#define LCD_RST_Pin GPIO_PIN_12		        //原来PA9
#define LCD_RST_GPIO_Port GPIOB 

#define LCD_RD_Pin GPIO_PIN_14		        //原来PA9
#define LCD_RD_GPIO_Port GPIOB

#define LCD_WR_Pin GPIO_PIN_15		        //原来PA9
#define LCD_WR_GPIO_Port GPIOB

#define ILI9341_LESS_PIXEL	  	   320	  // 液晶屏较短方向的像素宽度
#define ILI9341_MORE_PIXEL	 	     480	  // 液晶屏较长方向的像素宽度

#define ILI9341_DispWindow_X_Star  0      // 起始点的X坐标
#define ILI9341_DispWindow_Y_Star  0      // 起始点的Y坐标

extern uint16_t LCD_WIDTH, LCD_HEIGHT; 

//SPI INSTANCE
#define HSPI_INSTANCE		       &hspi2

#define BURST_MAX_SIZE 	       30

#define BLACK       0x0000      
#define NAVY        0x000F      
#define DARKGREEN   0x03E0      
#define DARKCYAN    0x03EF      
#define MAROON      0x7800      
#define PURPLE      0x780F      
#define OLIVE       0x7BE0      
#define LIGHTGREY   0xC618      
#define DARKGREY    0x7BEF      
#define BLUE        0x001F      
#define GREEN       0x07E0      
#define CYAN        0x07FF      
#define RED         0xF800     
#define MAGENTA     0xF81F      
#define YELLOW      0xFFE0      
#define WHITE       0xFFFF      
#define ORANGE      0xFD20      
#define GREENYELLOW 0xAFE5     
#define PINK        0xF81F

#define SCREEN_HORIZONTAL_1			0
#define SCREEN_VERTICA_1		    1
#define SCREEN_HORIZONTAL_2			2
#define SCREEN_VERTICA_2		    3
 
/* Define TFT String Mode */
#define TFT_STRING_MODE_NO_BACKGROUND		0x01
#define TFT_STRING_MODE_BACKGROUND			0x00

//定义液晶屏顺时针旋转方向 	0-0度旋转，1-90度旋转，2-180度旋转，3-270度旋转
#define USE_HORIZONTAL  	 0

void ILI9488_SPI_Init(void);
void ILI9488_SPI_Send(unsigned char SPI_Data);
void ILI9488_Write_Cmd(uint8_t Command);
void ILI9488_Write_Data(uint8_t Data);
void ILI9488_Write_CmdData(uint8_t Command,uint8_t Data);
void ILI9488_Write_Data16Bit(uint16_t Colour);
void ILI9488_SetWindows(uint16_t xStar, uint16_t yStar, uint16_t xEnd, uint16_t yEnd);

uint16_t ILI9488_GetWidth(void);
uint16_t ILI9488_GetHeight(void);
void ILI9488_SetRotation(uint8_t Rotation);


void ILI9488_Draw_Colour_Burst(uint16_t Colour, uint32_t Size);
void ILI9488_Fill_Screen(uint16_t Colour);

#endif

